﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;

using Newtonsoft.Json.Linq;

namespace KorbeRTR.MES
{
    public class HttpClientHelper
    {
        /// <summary>
        /// 服务器URL
        /// </summary>
        public static readonly string Url;

        /// <summary>
        /// 设备ID
        /// </summary>
        public static readonly string EquimentID;

        /// <summary>
        /// 设备IP
        /// </summary>
        public static readonly string IPAddress;

        /// <summary>
        /// 设备MAC
        /// </summary>
        public static readonly string MAC;

        public static string AuthString
        {
            get
            {
                var auth = new JObject();
                auth["Sign"] = "11463D95D5C94A1DABBDE2FDAA4CA1BF";
                auth["Pass"] = "F2D7D511B5C9A11192D1A0D512A5B646";
                return auth.ToString(Newtonsoft.Json.Formatting.None);
            }
        }

        private static readonly HttpClient client;

        static HttpClientHelper()
        {
            client = new HttpClient();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            client.DefaultRequestHeaders.Add("MsgHeader", AuthString);

            Url = ConfigurationManager.AppSettings["MES.Url"];
            EquimentID = ConfigurationManager.AppSettings["MES.EquimentID"];
            IPAddress = ConfigurationManager.AppSettings["MES.IPAddress"];
            MAC = ConfigurationManager.AppSettings["MES.MAC"];
        }

        private HttpClientHelper() {}

        public static HttpClient GetInstance()
        {
            return client;
        }
    }
}
